var ip = "http://123.57.207.22:8080";

function $ajax({ method = "get", url, data, success, error }) {
    var xhr = null;
    try {
        xhr = new XMLHttpRequest();
    } catch (error) {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (method == "get" && data) {
        url += "?" + data;
        console.log(url);
    }
    xhr.open(method, url, true);
    if (method == "get") {
        xhr.send();
    } else {
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(data);
    }
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
            if (xhr.status == 200) {
                if (success) {
                    var result = JSON.parse(xhr.responseText);
                    success(result);
                }
            } else {
                if (error) {
                    error("Error" + xhr.status);
                }
            }
        }
    }
}